Puppeteer babel不兼容

async function inside evaluate fails

Are you transforming your code with babel? The babel async function code isn’t compatible with Puppeteer. We call function.toString and send your code into Chromium, but babel messes with that and we end up sending an incomplete string. You can get around this by using template strings instead of functions.

1
2
3
await page.evaluate(`(async() => {
console.log('1');
})()`);

https://github.com/GoogleChrome/puppeteer/issues/1665

坚持原创技术分享,您的支持将鼓励我继续创作!